const { defineConfig } = require("@vue/cli-service");
const { list, car } = require("./src/mock");
const bodyParser = require('body-parser')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    setupMiddlewares(middlewares, devServer) {
      devServer.app.use(bodyParser.json())

      devServer.app.get("/api/list", (req, res) => {
        res.send({
          code: 200,
          data: list,
        });
      });

      devServer.app.get("/api/car", (req, res) => {
        res.send({
          code: 200,
          data: car,
        });
      });

      devServer.app.post("/api/car/detail", (req, res) => {
        const { id } = req.body;

        car.forEach(v => {
          const item = v.children.find(v => v.id === id)

          if(item) {
            res.send({
              code: 200,
              data: item.children
            })
          }
        })


        res.send({
          code: 200,
          data: car,
        });
      });

      return middlewares;
    },
  },
});
